<?php
/**
 *
 * @author griever
 * @version 
 */
require_once 'Base.php';
require_once 'Zend/Loader/PluginLoader.php';
require_once 'Zend/Controller/Action/Helper/Abstract.php';
require_once 'models/User.php';

/**
 * CheckPrimaryBInd Action Helper 
 * 
 * @uses actionHelper Custom_Helper
 */
class Custom_Helper_CheckPrimaryBind extends Dummy_Helper_Base {
	
	public function check($bind, $checkExist) {
		$error = null;
		if (! is_numeric ( $bind )) {
			$error = Message::PROFILE_ID_INVALID;
		} else {
			if ($checkExist == true) {
				$result = User::CheckItemAvailability ( 'primary_bind', $bind );
				if (! $result) {
					$error = Message::PROFILE_ALREADY_BOUND;
					return $error;
				}
			}
			$p = new Profile ( array ('profile_id' => $bind ) );
			if (! $p->isExist ()) {
				$error = Message::PROFILE_NOT_EXIST;
			}
		}
		return $error;
	}
	
	/**
	 * Strategy pattern: call helper as broker method
	 */
	public function direct($bind, $checkExist = false) {
		// TODO Auto-generated 'direct' method
		return $this->check ( $bind, $checkExist );
	}
}

